home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / X11R4 / cmds / X / ddx / mfb / RCS / mfbpushpxl.c,v < prev    next >
Encoding:
Text File  |  1990-02-15  |  7.3 KB  |  281 lines

  1. head     1.1;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.1
  10. date     90.02.14.19.58.21;  author tve;  state Exp;
  11. branches ;
  12. next     ;
  13.  
  14.  
  15. desc
  16. @Original X11R4 distribution
  17. @
  18.  
  19.  
  20.  
  21. 1.1
  22. log
  23. @Initial revision
  24. @
  25. text
  26. @/***********************************************************
  27. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
  28. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  29.  
  30.                         All Rights Reserved
  31.  
  32. Permission to use, copy, modify, and distribute this software and its 
  33. documentation for any purpose and without fee is hereby granted, 
  34. provided that the above copyright notice appear in all copies and that
  35. both that copyright notice and this permission notice appear in 
  36. supporting documentation, and that the names of Digital or MIT not be
  37. used in advertising or publicity pertaining to distribution of the
  38. software without specific, written prior permission.  
  39.  
  40. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  41. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  42. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  43. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  44. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  45. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  46. SOFTWARE.
  47.  
  48. ******************************************************************/
  49. /* $XConsortium: mfbpushpxl.c,v 5.2 89/09/14 16:26:57 rws Exp $ */
  50.  
  51. #include "X.h"
  52. #include "gcstruct.h"
  53. #include "scrnintstr.h"
  54. #include "pixmapstr.h"
  55. #include "miscstruct.h"
  56. #include "maskbits.h"
  57. #include "regionstr.h"
  58. #include "mfb.h"
  59.  
  60. /*  mfbSolidPP is courtesy of xhacks@@csri.toronto.edu
  61.  
  62.     For fillStyle==FillSolid, a monochrome PushPixels can be reduced to
  63.     a ROP in the following way:  (Note that the ROP is the same as the
  64.     result of ROP(src=0x3,dst=0x5))
  65.  
  66.             src=0011 0000 0011
  67.             dst=0101 0101 0101
  68.             rop      fg=0 fg=1
  69.     GXclear         0x0 0000 0100 0100 0
  70.     GXand           0x1 0001 0100 0101  s&d
  71.     GXandReverse    0x2 0010 0100 0110 s&~d
  72.     GXcopy          0x3 0011 0100 0111 s
  73.     GXandInverted   0x4 0100 0101 0100 ~s&d
  74.     GXnoop          0x5 0101 0101 0101 d
  75.     GXxor           0x6 0110 0101 0110 s^d
  76.     GXor            0x7 0111 0101 0111 s|d
  77.     GXnor           0x8 1000 0110 0100 ~s&~d
  78.     GXequiv         0x9 1001 0110 0101 ~s^d
  79.     GXinvert        0xa 1010 0110 0110 ~d
  80.     GXorReverse     0xb 1011 0110 0111 s|~d
  81.     GXcopyInverted  0xc 1100 0111 0100 ~s
  82.     GXorInverted    0xd 1101 0111 0101 ~s|d
  83.     GXnand          0xe 1110 0111 0110 ~s|~d
  84.     GXset           0xf 1111 0111 0111 1
  85.  
  86. For src=0: newRop = 0x4|(rop>>2)
  87. For src=1: newRop = 0x4|(rop&3)
  88. */
  89.  
  90. /* mfbSolidPP -- squeegees the forground color of pGC through pBitMap
  91.  * into pDrawable.  pBitMap is a stencil (dx by dy of it is used, it may
  92.  * be bigger) which is placed on the drawable at xOrg, yOrg.  Where a 1 bit
  93.  * is set in the bitmap, the fill style is put onto the drawable using
  94.  * the GC's logical function. The drawable is not changed where the bitmap
  95.  * has a zero bit or outside the area covered by the stencil.
  96.  */
  97. void
  98. mfbSolidPP(pGC, pBitMap, pDrawable, dx, dy, xOrg, yOrg)
  99.     GCPtr    pGC;
  100.     PixmapPtr    pBitMap;
  101.     DrawablePtr pDrawable;
  102.     int        dx, dy, xOrg, yOrg;
  103. {
  104.     unsigned char alu;
  105.     RegionRec rgnDst;
  106.     DDXPointPtr pptSrc;
  107.     BoxRec srcBox;
  108.     register DDXPointPtr ppt;
  109.     register BoxPtr pbox;
  110.     int i;
  111.  
  112.     if (!pGC->planemask & 1) return;
  113.  
  114.     /* compute the reduced rop function */
  115.     alu = pGC->alu;
  116.     if (!(pGC->fgPixel&1)) alu >>= 2;
  117.     alu = (alu & 0x3) | 0x4;
  118.     if (alu == GXnoop) return;
  119.  
  120.     srcBox.x1 = xOrg;
  121.     srcBox.y1 = yOrg;
  122.     srcBox.x2 = xOrg + dx;
  123.     srcBox.y2 = yOrg + dy;
  124.     (*pGC->pScreen->RegionInit)(&rgnDst, &srcBox, 1);
  125.  
  126.     /* clip the shape of the dst to the destination composite clip */
  127.     (*pGC->pScreen->Intersect)(&rgnDst, &rgnDst,
  128.                    ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip);
  129.  
  130.     if (!REGION_NIL(&rgnDst))
  131.     {
  132.     i = REGION_NUM_RECTS(&rgnDst);
  133.     pptSrc = (DDXPointPtr)ALLOCATE_LOCAL(i * sizeof(DDXPointRec));
  134.         if(pptSrc)
  135.         {
  136.         for (pbox = REGION_RECTS(&rgnDst), ppt = pptSrc;
  137.          --i >= 0;
  138.          pbox++, ppt++)
  139.         {
  140.         ppt->x = pbox->x1 - xOrg;
  141.         ppt->y = pbox->y1 - yOrg;
  142.         }
  143.         mfbDoBitblt((DrawablePtr)pBitMap, pDrawable, alu, &rgnDst, pptSrc);
  144.         DEALLOCATE_LOCAL(pptSrc);
  145.     }
  146.     }
  147.     (*pGC->pScreen->RegionUninit)(&rgnDst);
  148. }
  149.  
  150. #define NPT 128
  151.  
  152. /* mfbPushPixels -- squeegees the forground color of pGC through pBitMap
  153.  * into pDrawable.  pBitMap is a stencil (dx by dy of it is used, it may
  154.  * be bigger) which is placed on the drawable at xOrg, yOrg.  Where a 1 bit
  155.  * is set in the bitmap, the fill style is put onto the drawable using
  156.  * the GC's logical function. The drawable is not changed where the bitmap
  157.  * has a zero bit or outside the area covered by the stencil.
  158.  */
  159. void
  160. mfbPushPixels(pGC, pBitMap, pDrawable, dx, dy, xOrg, yOrg)
  161.     GCPtr    pGC;
  162.     PixmapPtr    pBitMap;
  163.     DrawablePtr pDrawable;
  164.     int        dx, dy, xOrg, yOrg;
  165. {
  166.     int        h, dxDiv32, ibEnd;
  167.     unsigned int *pwLineStart;
  168.     register unsigned int    *pw, *pwEnd;
  169.     register unsigned int mask;
  170.     register int ib, w;
  171.     register int ipt;        /* index into above arrays */
  172.     Bool     fInBox;
  173.     DDXPointRec    pt[NPT];
  174.     int        width[NPT];
  175.  
  176.     /* Now scan convert the pixmap and use the result to call fillspans in
  177.      * in the drawable with the original GC */
  178.     ipt = 0;
  179.     dxDiv32 = dx/32;
  180.     for(h = 0; h < dy; h++)
  181.     {
  182.  
  183.     pw = (unsigned int *)
  184.          (((char *)(pBitMap->devPrivate.ptr))+(h * pBitMap->devKind));
  185.     pwLineStart = pw;
  186.     /* Process all words which are fully in the pixmap */
  187.     
  188.     fInBox = FALSE;
  189.     pwEnd = pwLineStart + dxDiv32;
  190.     while(pw  < pwEnd)
  191.     {
  192.         w = *pw;
  193.         mask = endtab[1];
  194.         for(ib = 0; ib < 32; ib++)
  195.         {
  196.         if(w & mask)
  197.         {
  198.             if(!fInBox)
  199.             {
  200.             pt[ipt].x = ((pw - pwLineStart) << 5) + ib + xOrg;
  201.             pt[ipt].y = h + yOrg;
  202.             /* start new box */
  203.             fInBox = TRUE;
  204.             }
  205.         }
  206.         else
  207.         {
  208.             if(fInBox)
  209.             {
  210.             width[ipt] = ((pw - pwLineStart) << 5) + 
  211.                      ib + xOrg - pt[ipt].x;
  212.             if (++ipt >= NPT)
  213.             {
  214.                 (*pGC->ops->FillSpans)(pDrawable, pGC, NPT, pt,
  215.                                   width, TRUE);
  216.                 ipt = 0;
  217.             }
  218.             /* end box */
  219.             fInBox = FALSE;
  220.             }
  221.         }
  222.         mask = SCRRIGHT(mask, 1);
  223.         }
  224.         pw++;
  225.     }
  226.     ibEnd = dx & 0x1F;
  227.     if(ibEnd)
  228.     {
  229.         /* Process final partial word on line */
  230.         w = *pw;
  231.         mask = endtab[1];
  232.         for(ib = 0; ib < ibEnd; ib++)
  233.         {
  234.         if(w & mask)
  235.         {
  236.             if(!fInBox)
  237.             {
  238.             /* start new box */
  239.             pt[ipt].x = ((pw - pwLineStart) << 5) + ib + xOrg;
  240.             pt[ipt].y = h + yOrg;
  241.             fInBox = TRUE;
  242.             }
  243.         }
  244.         else
  245.         {
  246.             if(fInBox)
  247.             {
  248.             /* end box */
  249.             width[ipt] = ((pw - pwLineStart) << 5) + 
  250.                      ib + xOrg - pt[ipt].x;
  251.             if (++ipt >= NPT)
  252.             {
  253.                 (*pGC->ops->FillSpans)(pDrawable, pGC, NPT, pt,
  254.                                   width, TRUE);
  255.                 ipt = 0;
  256.             }
  257.             fInBox = FALSE;
  258.             }
  259.         }
  260.         mask = SCRRIGHT(mask, 1);
  261.         }
  262.     }
  263.     /* If scanline ended with last bit set, end the box */
  264.     if(fInBox)
  265.     {
  266.         width[ipt] = dx + xOrg - pt[ipt].x;
  267.         if (++ipt >= NPT)
  268.         {
  269.         (*pGC->ops->FillSpans)(pDrawable, pGC, NPT, pt, width, TRUE);
  270.         ipt = 0;
  271.         }
  272.     }
  273.     }
  274.     /* Flush any remaining spans */
  275.     if (ipt)
  276.     {
  277.     (*pGC->ops->FillSpans)(pDrawable, pGC, ipt, pt, width, TRUE);
  278.     }
  279. }
  280. @
  281.